'use strict';

const Controller = require('./base');

class MemberController extends Controller {

  async create() {
    const createRule = {
      userId: { type: 'string' },
      userNickName: { type: 'string' },
      userFace: { type: 'string' },
      userPower: { type: 'number' },
      vipLevel: { type: 'number' },
    };
    // 校验参数
    this.ctx.validate(createRule);

    console.log(this.ctx.request.body, 'this.ctx.request.body');

    const member = Object.assign(this.ctx.request.body, {});

    await this.ctx.service.member.create(member);

    this.success();
  }

  async find() {

    const memberId = this.ctx.params.id;

    console.log(memberId, 'memberId');

    const member = await this.ctx.service.member.findById(memberId);

    this.success(member);
  }

  async findAll() {

    const members = await this.ctx.service.member.findAll();

    this.success(members);
  }
}

module.exports = MemberController;
